<?php
/*

SHOPPERPRESS DEVELOPED BY MARK FAIL
http://www.markfail.com
http://www.shopperpress.com

Follow on twitter: http://www.twitter.com/markfail
Follow on twitter: http://www.twitter.com/shopperpress

*/
	session_id($_GET['sid']);
	session_start();
	
	include_once('../../functions.php');
 	
	if($_GET['newprice']) {
		//protect against going below zero
		updateQty();
		$_SESSION['ddc']['price'] = updatePrice();
	}
	
	if($_GET['action'] == "addproduct") {
 
		if(!isset($_SESSION['ddc']['productsincart'][$_GET['id']])) {

			$_SESSION['ddc']['productsincart'][$_GET['id']] = 0;
			//new array for this product info			
			$_SESSION['ddc'][$_GET['id']]['size'] 			= $_GET['size'];
			$_SESSION['ddc'][$_GET['id']]['color'] 			= $_GET['color'];
			$_SESSION['ddc'][$_GET['id']]['shipping'] 		= $_GET['ship'];
			$_SESSION['ddc'][$_GET['id']]['extra'] 			= $_GET['extra'];
			$_SESSION['ddc']['productsincart'][$_GET['id']]++;
			//$_GET['qty']--;
			$ID4QTY = $_GET['id'];
			
 		} else {


			if( isset($_GET['size']) && strlen($_GET['size']) > 1 ){

						$ID4QTY = $_GET['id']."000".date("s");
						$_SESSION['ddc'][$ID4QTY]['main_ID'] 	= $_GET['id'];
						$_SESSION['ddc']['productsincart'][$ID4QTY] = 0;
						//new array for this product info			
						$_SESSION['ddc'][$ID4QTY]['size'] 		= $_GET['size'];
						$_SESSION['ddc'][$ID4QTY]['color'] 		= $_GET['color'];
						$_SESSION['ddc'][$ID4QTY]['shipping'] 	= $_GET['ship'];
						$_SESSION['ddc'][$ID4QTY]['extra'] 		= $_GET['extra'];
						$_SESSION['ddc']['productsincart'][$ID4QTY]++;
						

			}else{
 
			$_SESSION['ddc']['productsincart'][$_GET['id']]++;
			$ID4QTY = $_GET['id'];

			}
		}

		while($_GET['qty'] > 1){
			$_SESSION['ddc']['productsincart'][$ID4QTY]++;
			$_GET['qty']--;
		}


		updateQty();
		updatePrice();
		
	}

 	
	if($_GET['action'] == "removeproduct") {

 		if($_SESSION['ddc']['productsincart'][$_GET['id']] == 1) {

			unset($_SESSION['ddc']['productsincart'][$_GET['id']]);
			unset($_SESSION['ddc'][$_GET['id']]['size']);

		} else {
			$_SESSION['ddc']['productsincart'][$_GET['id']]--;
		}
		updateQty();
		updatePrice();
	}	


	if($_GET['action'] == "increaseQty") {

		$_SESSION['ddc']['productsincart'][$_GET['id']]++;
		
		updateQty();
		updatePrice();
	}	
	
	if($_GET['action'] == "removeproductallqty") {
		unset($_SESSION['ddc']['productsincart'][$_GET['id']]);

		updateQty();
		updatePrice();
	}
	
	if($_GET['action'] == "changeqty") {	
		$_SESSION['ddc']['productsincart'][$_GET['id']] = $_GET['qty'];
		updateQty();
		$_SESSION['ddc']['price'] = updatePrice();
	}
	
	if($_GET['action'] == "gettotal") {	
		updateQty();
		echo updatePrice();
	}
 
	updatePrice();
	updateQty();
	$_SESSION['ddc']['price'] = updatePrice();
	
	session_write_close();	
?>